package com.huluobo.a2308douyindemo.demo

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.animation.AnimationUtils
import androidx.databinding.DataBindingUtil.setContentView
import com.huluobo.a2308douyindemo.R
import com.huluobo.a2308douyindemo.databinding.ActivityAninBinding
import com.huluobo.a2308douyindemo.login.LoginViewModel
import com.huluobo.a2308douyindemo.mvvm.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AnimActivity : BaseActivity<ActivityAninBinding, LoginViewModel>() {
    override fun initData() {
    }

    override fun initView() {
        binding.transitionBtn.setOnClickListener {
            //通过动画工具可以获取到xml中的动画
            val tran = AnimationUtils.loadAnimation(this, R.anim.translate)
            //设置动画时长
            tran.duration = 1000
            //启动动画
            binding.animIv.startAnimation(tran)
        }

        binding.rotationBtn.setOnClickListener {
            val rotation = AnimationUtils.loadAnimation(this, R.anim.rotate)
            rotation.duration = 1000
            binding.animIv.startAnimation(rotation)
        }

        binding.scaleBtn.setOnClickListener {
            val scale = AnimationUtils.loadAnimation(this, R.anim.scale)
            scale.duration = 1000
            binding.animIv.startAnimation(scale)
        }

        binding.alphaBtn.setOnClickListener {
            val alpha = AnimationUtils.loadAnimation(this, R.anim.alpha)
            alpha.duration = 1000
            binding.animIv.startAnimation(alpha)
        }

        binding.setBtn.setOnClickListener {
            val set = AnimationUtils.loadAnimation(this, R.anim.anim_set)
            set.duration = 1000
            binding.animIv.startAnimation(set)
        }


        binding.valueBtn.setOnClickListener {
            //修改值的属性动画
            //声明属性变化 从0到500
            val valueAnimator = ValueAnimator.ofFloat(0f, 21600f)
            //设置时长
            valueAnimator.duration = 1000
            valueAnimator.addUpdateListener {
                Log.e("TagA", "rotation的旋转角度:${it.animatedValue as Float}")
                binding.animIv.rotation = it.animatedValue as Float
            }
            valueAnimator.start()
        }

        binding.objectBtn.setOnClickListener {
            //修改图片资源为对号
            binding.animIv.setImageResource(R.drawable.baseline_check_24)
            //对象的属性动画,可以直接作用到目标对象上 透明度 alpha 缩放 scaleX scaleY 平移 translationX translationY 旋转 rotation
            val alpha = ObjectAnimator.ofFloat(binding.animIv, "alpha", 1f, 0f)
            alpha.duration = 1000
            alpha.start()
        }

        binding.headerBtn.setOnClickListener {
            //先设置透明度为1,完全显示出来
            binding.animIv.alpha = 1f
            binding.animIv.setImageResource(R.drawable.ic_add)
        }


    }
}